import {HttpContext} from '@angular/common/http';
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit} from '@angular/core';
import {ALLOW_ANONYMOUS} from '@delon/auth';
import {_HttpClient, ModalHelper, SettingsService} from '@delon/theme';
import {NzMessageService} from 'ng-zorro-antd/message';
import {ChangePasswordComponent} from 'src/app/layout/change/change.component';
import {Api} from 'src/app/shared/api/api';
import {ResponseCode} from 'src/app/shared/response.code';

@Component({
  selector: 'app-account-profile-security',
  templateUrl: './security.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class ProfileSecurityComponent implements OnInit {
  user: any;
  securityInfo: any = {};
  constructor(
    private settings: SettingsService,
    private http: _HttpClient,
    private modal: ModalHelper,
    public msg: NzMessageService,
    public changeDetectorRef: ChangeDetectorRef
  ) {}

  ngOnInit(): void {
    this.user = this.settings.user;
    this.getSecurityInfo();
    this.user.password
  }

  changePassword() {
    console.log('change password');
    this.modal.createStatic(ChangePasswordComponent).subscribe();
  }

  getSecurityInfo() {
    this.http
      .get(
        Api.BaseCustomerApi,
        {
          userId: localStorage.getItem('user_id')
        },
        { context: new HttpContext().set(ALLOW_ANONYMOUS, true) }
      )

      .subscribe((res: any) => {
        if (res && res.code === ResponseCode.SUCCESS) {
          if (res.data) {
            this.securityInfo = res.data;
            this.changeDetectorRef.markForCheck();
            this.changeDetectorRef.detectChanges();
          }
        }
      });
  }
}
